<template>
  <div class="ticket_item" @click='handleClick(data)'>
    <div class="title">
      <p
        class="state"
        :style="{
          backgroundColor: colorList[data.state],
          color: data.state == 3 ? '#0A92FE' : '',
        }"
      >
        {{ stateList[data.state] || '完成' }}
      </p>
      <p class="number">工单编号: {{ data.number || '-' }}</p>
    </div>
    <div class="item">
      <div class="info_item" v-for="item in infos" :key="item.icon">
        <van-image :src="item.icon" class="icon_img">
          <template v-slot:loading>
            <van-loading type="spinner" size="20" />
          </template>
        </van-image>
        <span> {{ item.name }}: </span>
        <span class="item_val"> {{ data[item.key] || '-' }}</span>
      </div>
    </div>
    <div class="item_bottom">
      <p>上报人:{{ data.reporterName || '-' }}</p>
      <p>截止日期:{{ data.updateTime || '-' }}</p>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import error from '@/assets/images/error.png';
import decv from '@/assets/images/decv.png';
import local from '@/assets/images/local.png';
const props = defineProps({
  icon: {
    type: String,
    required: '',
  },
  data: {
    type: Object,
    default: () => {
      return {};
    },
  },
  stateList: {
    type: Array,
    default: () => {
      return ['一般', '严重', '紧急', '完成'];
    },
  },
  colorList: {
    type: Array,
    default: () => {
      return ['#0A92FE', '#EA7949', '#EA4949', '#E8F1FF'];
    },
  },
});

const infos = ref([
  { icon: error, name: '设备名称', key: 'deviceTypeName' },
  { icon: decv, name: '安装位置', key: 'installLocation' },
  { icon: local, name: '异常项', key: 'item' },
]);


const emit = defineEmits(['handleClick'])

function handleClick (data) {
 emit('handleClick',data) 
}

</script>

<style lang="scss" scoped>
.ticket_item {
  padding-top: 12px;
  padding-left: 12px;
  width: 100%;
  font-weight: bold;
  margin: 12px 0;
  border-bottom: 1px solid rgba(227, 227, 227, 0.2);
  .item {
    line-height: 40px;
    font-weight: 400;
    font-size: 13px;
    color: #666666;
  }
  .title {
    display: flex;
    gap: 0 24px;
    .state {
      color: #ffffff;
      width: 54px;
      height: 22px;
      line-height: 22px;
      text-align: center;
      border-radius: 2px;
    }
    .number {
      height: 24px;
      font-weight: bold;
      font-size: 14px;
      color: #333333;
    }
  }

  .info_item {
    height: 24px;
    margin: 4px 0;
    height: 24px;
    font-weight: 400;
    font-size: 13px;
    color: #666666;
    line-height: 24px;
  }
  .icon_img {
    position: relative;
    top: 2px;
    margin-right: 4px;
  }
  .item_bottom {
    display: flex;
    justify-content: space-between;
    height: 24px;
    font-weight: 400;
    font-size: 13px;
    color: #2c64a4;
    line-height: 24px;
    p {
      width: 50%;
    }
  }
}
</style>
